<?php
class Comment extends Base
{
    private $_commentId;
    private $_title;
    private $_content;
    private $_pid;
    private $_userId;
    private $_type;
    private $_createDate;
    private $_operatorId;

    protected function getPrimaryKey()
    {
        return "commentId";
    }

    protected function getTableName()
    {
        return "comment";
    }

    public function setCommentId($commentId)
    {
        $this->_commentId = $commentId;
    }

    public function getCommentId()
    {
        return $this->_commentId;
    }

    public function setContent($content)
    {
        $this->_content = $content;
    }

    public function getContent()
    {
        return $this->_content;
    }

    public function setCreateDate($createDate)
    {
        $this->_createDate = $createDate;
    }

    public function getCreateDate()
    {
        return $this->_createDate;
    }

    public function setOperatorId($operatorId)
    {
        $this->_operatorId = $operatorId;
    }

    public function getOperatorId()
    {
        return $this->_operatorId;
    }

    public function setPid($pid)
    {
        $this->_pid = $pid;
    }

    public function getPid()
    {
        return $this->_pid;
    }

    public function setTitle($title)
    {
        $this->_title = $title;
    }

    public function getTitle()
    {
        return $this->_title;
    }

    public function setType($type)
    {
        $this->_type = $type;
    }

    public function getType()
    {
        return $this->_type;
    }

    public function setUserId($userId)
    {
        $this->_userId = $userId;
    }

    public function getUserId()
    {
        return $this->_userId;
    }

    public function getOperator()
    {
        if ($this->getType() == "NEWS") {
            $news = $this->loadModule("News");
            return $news->load($this->getOperatorId());
        }
        if ($this->getType() == "ACTIVITY") {
            $news = $this->loadModule("Activity");
            return $news->load($this->getOperatorId());
        }
    }

    public function findByOperatorIdAndType($operatorId, $operatorType)
    {
        $sql = "select c.*,u.userName as userName from comment c left join user u on c.userId = u.userId where c.operatorId ='$operatorId' and c.type = '$operatorType' order by c.createDate desc";
        return $this->_db->getall($sql);
    }

    protected function competeRecord($post)
    {
        $c = $this->getCredentials();
        return array(
            "content" => htmlspecialchars($post['content']),
            "userId" => $c['userId'],
            "type" => $post['type'],
            "createDate" => Util::getCurrentDate(),
            "operatorId" => $post['operatorId']
        );
    }

    public function findMyCommentsByOperatorIdAndType($operatorId, $operatorType, $count)
    {
        $c = $this->getCredentials();
        $sql = "select * from comment where operatorId ='$operatorId' and type = '$operatorType' and userId= " . $c['userId'] . " order by createDate desc limit $count";
        return $this->_db->getall($sql);
    }


}

?>